using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using System.Net;

using PickGold;
using PickGold.Database;
using PickGold.Entities.Table;

namespace PickGold.Base
{
    public class CIpinfo : CExtendIpInfo
    {
        //
        public const string IP_POINT = "ip_point";
        public const string IP_ADDRESS = "ip_address";
        public const string FULL_ADDRESS = "full_address";
        //
        private IKernel _Kernel;
        //
		public CIpinfo(IKernel kernel) : base(kernel.Database)
        {
            this.setKernel(kernel);
        }
        //
		public void setKernel(IKernel value)
        {
			this._Kernel = value;
            base.Database = value.Database;
        }
        //
        public string IpAddress
        {
            set
            {
                this.ItemIp = GetIpValue(value);
            }
            get
            {
                return GetIpValue(this.ItemIp);
            }
        }
        //
        public static string GetIpValue(long ip)
        {
            try
            {
                return new IPAddress(ip).ToString();
            }
            catch
            {
            }
            return string.Empty;
        }
        public static long GetIpValue(string ip)
        {
            try
            {
                return IPAddress.Parse(ip).Address;
            }
            catch
            {
            }
            return 0;
        }
        //
        public static string GetIpAddress(long ip)
        {
            return GetIpValue(ip);
        }
        public static string GetIpAddress(object ip)
        {
            if (ip == null)
                return GetIpAddress(0);
            return GetIpAddress(CParser.ConvertTo<long>(ip));
        }
        //
        public static long GetIpPoint(string ip)
        {
            return GetIpValue(ip);
        }
        public static long GetIpPoint(object ip)
        {
            if (ip == null)
                return GetIpValue(null);
            return GetIpValue(ip.ToString());
        }
        //
    }
    //
}
//
